﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum WallType
{
    MUQIANG,
    SHIQIANG,
}

public class WallParent : MonoBehaviour
{
    public GameObject effect;
    public GameObject[] skin;
    public WallType wallType;
    public int life = 3;

    public void PengZhuang()
    {
        StopAllCoroutines();
        StartCoroutine(EnableOtherCollider());
        if (effect != null)
        {
            effect.SetActive(true);
            effect.GetComponent<ParticleSystem>().Play();
        }
        life = life - 1;
        if (life <= 0)
            StartCoroutine(DestroyMyself());
        else
        {
            for (int i = 0; i < skin.Length; i++)
                skin[i].SetActive(i == life - 1);
        }
    }


    IEnumerator EnableOtherCollider()
    {
        if (GetComponent<Animation>() != null)
            GetComponent<Animation>().Play("Take 001");
        for (int i = 0; i < transform.childCount; i++)
            if (transform.GetChild(i).GetComponent<BoxCollider>() != null)
                transform.GetChild(i).GetComponent<BoxCollider>().enabled = false;
        yield return new WaitForSeconds(1f);
        for (int i = 0; i < transform.childCount; i++)
            if (transform.GetChild(i).GetComponent<BoxCollider>() != null)
                transform.GetChild(i).GetComponent<BoxCollider>().enabled = true;
    }

    IEnumerator DestroyMyself()
    {
        yield return new WaitForSeconds(1f);
        Destroy(this.gameObject);
    }
}